<?php

include_once("core/controller.php");
include_once("core/libs/file.php");
include_once("core/versionHandler.php");
/**
 * This Controller is used to install a module
 * @copyright inovia
 * @package oolime_manager 
 *
 */
class InstallModule extends Controller {
   
   
  //todo verifier le niveau d'utilisateur
  protected function isLegitimate(){
    if(!$this->request->exist(Array("surname")) || !$this->request->exist(Array("number"))) {
      $this->response->addError("Enter the name and number of the module to install.");
      return false;
    }
    return true;
  }



  /**
  * Function doing the actions of the Controller
  * 
  */
  protected function actions(){
    //recuperer des infos
    
    $version = new Version("");
    $root    = new DOMElement('MyVersion');
    $this->response->doc->appendChild($root);
    $t       = $version->exportXML($this->response->doc);            
    $root->appendChild($t);
    $this->response->add($root);
    
    $moduleH  = new VersionHandler("packages/modules/mod_*");
    $mod      = $moduleH->getModByName($this->request->get('surname')); 
    $root2    = new DOMElement('RequestedModule');
    $this->response->doc->appendChild($root2);
    $t2       = $mod->exportXML($this->response->doc);            
    $root2->appendChild($t2);
    $this->response->add($root2);
    
    $nameSource=$mod->path;
    //echo $mod->path;
    $tab = $mod->getcontainsD();
    if(count($tab)){
      foreach($tab as $pathDir){
        dircopy($nameSource."/".$pathDir,$pathDir);
      }
    }
    
    $tab = $mod->getcontainsF();
    if(count($tab)){
      foreach($tab as $pathF){
        $f = new File($pathF,"w");
        fcopy($nameSource."/".$pathF,$pathF);
      }
    }
   
    //recuperer des tables...
    //$this->globals->dataBase->exportTables(Array("eventdispatcher","user"),"export/export.sql.gz");
  
    //recuperer des fichiers
    //copy("http://www.google.fr","here");
    
    //Update Dispatcher
  
    $this->response->setXSLT("views/manager/installMod.xsl");

 }


   /**
    * Function doing default actions of the Controller
    *
    */
   protected function defaultActions(){
      
   }

}



?>
